#!/sbin/sh

OUTFD=/proc/self/fd/$2;
ZIP="$3";
DIR=`dirname "$ZIP"`;

ui_print() {
  until [ ! "$1" ]; do
    echo -e "ui_print $1\nui_print" > $OUTFD;
    shift;
  done;
}
show_progress() { echo "progress $1 $2" > $OUTFD; }
set_perm_recursive() {
  dirs=$(echo $* | awk '{ print substr($0, index($0,$5)) }');
  for i in $dirs; do
    chown -R $1.$2 $i; chown -R $1:$2 $i;
    find "$i" -type d -exec chmod $3 {} +;
    find "$i" -type f -exec chmod $4 {} +;
  done;
}
file_getprop() { grep "^$2" "$1" | cut -d= -f2; }
getprop() { test -e /sbin/getprop && /sbin/getprop $1 || file_getprop /default.prop $1; }
abort() { ui_print "$*"; exit 1; }

mkdir -p /tmp/anykernel;
cd /tmp/anykernel;
unzip -o "$ZIP";
ui_print "**********************";
ui_print " wulan17 Kernel Test Build";
ui_print "**********************";
/sbin/busybox mount /system;
ui_print "**********************";
ui_print " Installing patch";
ui_print "**********************";
/sbin/busybox mount /system;

ui_print "- Starting kernel installation...";
/sbin/sh /tmp/anykernel/anykernel.sh;

ui_print "- Kernel installation completed";